package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MineUserTraining;
import com.ruoyi.system.service.IMineUserTrainingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户培训Controller
 * 
 * @author ruoyi
 * @date 2025-01-15
 */
@RestController
@RequestMapping("/system/user_training")
public class MineUserTrainingController extends BaseController
{
    @Autowired
    private IMineUserTrainingService mineUserTrainingService;

    /**
     * 查询用户培训列表
     */
    @PreAuthorize("@ss.hasPermi('system:user_training:list')")
    @GetMapping("/list")
    public TableDataInfo list(MineUserTraining mineUserTraining)
    {
        startPage();
        List<MineUserTraining> list = mineUserTrainingService.selectMineUserTrainingList(mineUserTraining);
        return getDataTable(list);
    }

    /**
     * 导出用户培训列表
     */
    @PreAuthorize("@ss.hasPermi('system:user_training:export')")
    @Log(title = "用户培训", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MineUserTraining mineUserTraining)
    {
        List<MineUserTraining> list = mineUserTrainingService.selectMineUserTrainingList(mineUserTraining);
        ExcelUtil<MineUserTraining> util = new ExcelUtil<MineUserTraining>(MineUserTraining.class);
        util.exportExcel(response, list, "用户培训数据");
    }

    /**
     * 获取用户培训详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:user_training:query')")
    @GetMapping(value = "/{userTrainingId}")
    public AjaxResult getInfo(@PathVariable("userTrainingId") Long userTrainingId)
    {
        return success(mineUserTrainingService.selectMineUserTrainingByUserTrainingId(userTrainingId));
    }

    /**
     * 根据用户ID查询用户培训记录
     */
    @PreAuthorize("@ss.hasPermi('system:user_training:query')")
    @GetMapping(value = "/user/{userId}")
    public AjaxResult getByUserId(@PathVariable("userId") Long userId)
    {
        List<MineUserTraining> list = mineUserTrainingService.selectMineUserTrainingByUserId(userId);
        return success(list);
    }

    /**
     * 根据培训ID查询用户培训记录
     */
    @PreAuthorize("@ss.hasPermi('system:user_training:query')")
    @GetMapping(value = "/training/{trainingId}")
    public AjaxResult getByTrainingId(@PathVariable("trainingId") Long trainingId)
    {
        List<MineUserTraining> list = mineUserTrainingService.selectMineUserTrainingByTrainingId(trainingId);
        return success(list);
    }

    /**
     * 新增用户培训
     */
    @PreAuthorize("@ss.hasPermi('system:user_training:add')")
    @Log(title = "用户培训", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MineUserTraining mineUserTraining)
    {
        return toAjax(mineUserTrainingService.insertMineUserTraining(mineUserTraining));
    }

    /**
     * 修改用户培训
     */
    @PreAuthorize("@ss.hasPermi('system:user_training:edit')")
    @Log(title = "用户培训", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MineUserTraining mineUserTraining)
    {
        return toAjax(mineUserTrainingService.updateMineUserTraining(mineUserTraining));
    }

    /**
     * 删除用户培训
     */
    @PreAuthorize("@ss.hasPermi('system:user_training:remove')")
    @Log(title = "用户培训", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userTrainingIds}")
    public AjaxResult remove(@PathVariable Long[] userTrainingIds)
    {
        return toAjax(mineUserTrainingService.deleteMineUserTrainingByUserTrainingIds(userTrainingIds));
    }
}
